﻿<cfsilent>
	<cfscript>
		
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		userArray = arrayNew(1);
	
		keyword = trim(event.getArg('Keywords'));
		userType = event.getArg('userType');
		
		if ( len(keyword) ) {
			writeLog( text=userType);
			if( userType eq '1'){
				
				sql = "SELECT 
							t_teacher.tch_id, 
							t_teacher.tch_name, 
							t_teacher.tch_sex 
						FROM 
							t_teacher 
						WHERE 
							t_teacher.tch_id LIKE :keyword 
							OR 
							t_teacher.tch_name LIKE :keyword 
						ORDER BY 
							t_teacher.tch_name ASC  ";
				queryObj = new query( datasource=application.dnsSlave, maxRows=18 );
				queryObj.addParam( name="keyword", value=keyword & '%', cfsqltype="cf_sql_varchar" );
				rs_teacher = queryObj.execute( sql=sql ).getResult();
					
				for ( i=1; i LTE rs_teacher.recordCount; i++){
					arrayAppend(userArray,[rs_teacher["tch_id"][i],rs_teacher["tch_name"][i],rs_teacher["tch_sex"][i] ]);
				}
				
			}else{
				sql = "SELECT 
							stu_id ,
							stu_name,
							stu_sex 
						FROM 
							t_student 
						WHERE 
							t_student.stu_id LIKE :keyword 
							OR 
							t_student.stu_name LIKE :keyword 
						ORDER BY 
							t_student.stu_name ASC  ";
				queryObj = new query( datasource=application.dnsSlave, maxRows=18 );
				queryObj.addParam( name="keyword", value=keyword & '%', cfsqltype="cf_sql_varchar" );
				rs_student = queryObj.execute( sql=sql ).getResult();
					
				for ( i=1; i LTE rs_student.recordCount; i++){
					arrayAppend(userArray,[rs_student["stu_id"][i],rs_student["stu_name"][i],rs_student["stu_sex"][i] ]);
				}
			}
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:userArray, stringNumbers:true)#</cfoutput>